package sg.edu.nus.iss.jass.datastore;

import java.util.List;
import java.util.Properties;


/**
 * <p>Transform data between java Properties and java bean that is subclass of BaseDTO</P>
 * 
 * Any error about unmatched class name, attribute name are ignored.
 * 
 * @author WANG DAYONG
 *
 */
public interface IDataMapper {
	
	/**
	 * The concatenate character between attribute name and the identifier
	 */
	public static final String SEPARATOR_CHAR = "_";
	

	/**
	 * The key to keep the class name of object to be transformed
	 */
	public static final String TABLE_NAME = "META-TABLE-NAME";
	
	/**
	 * <p>To map java Properties to collection of objects</p>
	 * 
	 * The target object class name is stored in the given Properties, 
	 * and it can be get by key <i>META-TABLE-NAME</i>.</br>
	 * All the keys in Properties ending with '_{id}' should be split 
	 * by the last '_', the first part is the attribute name, the second part is the value of id.
	 * 
	 * @param prop The source Properties is to be parsed
	 * @return
	 * 			Parsed collection of objects
	 */
	public List<? extends BaseDTO> mapProperties2Object(Properties prop);
	
	/**
	 * <p>To transform collection of objects to java Properties</p>
	 * 
	 * The object in given collection will be parsed to key/value pairs.</br>
	 * The key must be the attribute name of object in given list plus '_{id}', 
	 * {id} is the value of id of the object in the given list, the combination is to keep the same attribute unique. </br>
	 * Any non-primitive type in the object excluding java.util.Date, java.util.Calendar will be ignored without warning.</br>
	 * The class name of object in given collection is required to save in java Properties as key 'META-TABLE-NAME'
	 * 
	 * @param list The source collection of object need to be transformed
	 * @return	Transformed key/value pairs stored in java Properties
	 */
	public Properties mapObject2Properties(List<? extends BaseDTO> list);
	
	
}
